package com.yanqu.road.dao.impl.activity.tonbing.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.tonbing.config.TonBingBuffTypeConfig;
import com.yanqu.road.utils.date.DateHelper;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TonBingBuffTypeConfigDaoImpl extends TempDao {

    private static String getTonBingBuffTypeConfigSql = "select * from `t_s_activity_peaktongbing_buff` where `activityId`=?";

    public Map<Integer, TonBingBuffTypeConfig> getTonBingBuffTypeConfigLMap(int activityId) {
        Map<Integer, TonBingBuffTypeConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getTonBingBuffTypeConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                TonBingBuffTypeConfig data = new TonBingBuffTypeConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setType(rs.getInt("type"));
                data.setIcon(rs.getInt("icon"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setBuffEffect(rs.getString("buffEffect"));
                data.setContinueTime(DateHelper.HOUR_MILLIONS * rs.getInt("continueTime"));
                map.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
